package sealte.util.math;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 随机数辅助类
 * @author SEALTE
 */
public class RandomUtil {

	private static Map<Integer, String> letterMap = new HashMap<Integer, String>();

	static {
		letterMap.put(0, "A");
		letterMap.put(1, "B");
		letterMap.put(2, "C");
		letterMap.put(3, "D");
		letterMap.put(4, "E");
		letterMap.put(5, "F");
		letterMap.put(6, "G");
		letterMap.put(7, "H");
		letterMap.put(8, "I");
		letterMap.put(9, "J");
		letterMap.put(10, "K");
		letterMap.put(11, "L");
		letterMap.put(12, "M");
		letterMap.put(13, "N");
		letterMap.put(14, "O");
		letterMap.put(15, "P");
		letterMap.put(16, "Q");
		letterMap.put(17, "R");
		letterMap.put(18, "S");
		letterMap.put(19, "T");
		letterMap.put(20, "U");
		letterMap.put(21, "V");
		letterMap.put(22, "W");
		letterMap.put(23, "X");
		letterMap.put(24, "Y");
		letterMap.put(25, "Z");
	}
	
	/**
	 * 产生0-range范围内的整型随机数
	 * @param range 随机数最大范围
	 * @return 0-range范围内的整型随机数
	 */
	public static int getRandomInteger(int range){
		return (int)(Math.random() * range);
	}
	
	/**
	 * 随机产生26个大写英文字母中的某一个
	 * @return 某个大写的英文字母
	 */
	public static String getRandomLetter(){
		return letterMap.get(getRandomInteger(25));
	}
	
	/**
	 * 随机产生规定位数的字符串
	 * @param length 要产生的字符串长度
	 * @return 给定长度的字符串(由大写字母组成)
	 */
	public static String getRandomWord(int length){
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<length;i++){
			sb.append(getRandomLetter());
		}
		return sb.toString();
	}
	
	/**
	 * 随机产生一个JAVA的UUID
	 * @return JAVA版本的UUID
	 */
	public static String randomUUID(){
		return UUID.randomUUID().toString();
	}
	
}
